/*
 * FileProtocolServer.h
 *
 *  Created on: 26/06/2014
 *      Author: Caina
 */

#ifndef FILEPROTOCOLSERVER_H_
#define FILEPROTOCOLSERVER_H_

#include <cstdio>
#include <vector>
#include <string>

#include "TCPSocket.h"
#include "Thread.h"
#include "Globals.h"
#include "MessageTypes.h"
#include "SDL2/SDL.h"
#include "User.h"
#include "ByteQueue.h"
#include "File.h"
#include "FileTable.h"

class FileProtocolServer {
private:
	TCPSocket socket;

	static void handle_file_table(ByteQueue& queue);
	static void handle_new_user(ByteQueue& queue);
	static void handle_incoming_file(ByteQueue& queue);
	static void handle_send_file_to(ByteQueue queue);
	static void handle_delete_file(ByteQueue& queue);
	static void handle_rename_file(ByteQueue& queue);
	static void handle_relocate_file_to(ByteQueue& queue);
	static void handle_create_directory(ByteQueue& queue);
	static void handle_delete_directory(ByteQueue& queue);
	static void handle_rename_directory(ByteQueue& queue);
	static void handle_peers(ByteQueue& queue);
	static void handle_user_table(ByteQueue& queue);

	static std::string convert_ip_to_string(unsigned int ip);

public:
	FileProtocolServer();
	virtual ~FileProtocolServer();
	static void handle_message(TCPSocket socket);
	void run();
};

#endif /* FILEPROTOCOLSERVER_H_ */
